package com.shsc.example.project;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class ViewActivity extends AppCompatActivity {

    private TextView mTvName;
    private Button mBtChangeName;
    private EditText mEtName;
    private Button mBtToWeb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置布局
        setContentView(R.layout.activity_view);

        // 布局里面的组件找出来
        mTvName = (TextView) findViewById(R.id.tv_name);
        mBtChangeName = (Button) findViewById(R.id.bt_change_name);
        mEtName = (EditText) findViewById(R.id.et_name);
        mBtToWeb = (Button) findViewById(R.id.bt_to_web);

        mBtChangeName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvName.setText(mEtName.getText());
//                addView();
            }
        });

        mBtToWeb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(ViewActivity.this, WebActivity.class));
            }
        });
    }

//    /**
//     * 动态添加view
//     */
//    public void addView() {
//        ConstraintLayout clContent = (ConstraintLayout) findViewById(R.id.cl_content);
//        EditText newEtSexView = new EditText(this);
//
//        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(500, ConstraintLayout.LayoutParams.WRAP_CONTENT);
//        layoutParams.leftToLeft = clContent.getId();
//        layoutParams.rightToRight = clContent.getId();
//        layoutParams.topToBottom = mEtName.getId();
//        layoutParams.topMargin = 20;
//        clContent.addView(newEtSexView,  layoutParams);
//    }
}